import Vue from 'vue'
import App from './App.vue'
import router from './components/route'
import ElementUi from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css';
import './assets/css/icon-css/iconfont.css'
const echarts = require('echarts');
import MyPlugin from './assets/js/plugin'
import axios from 'axios'
import Vueaxios from 'vue-axios'
// 引入国际化插件，设定不同的语言文本
import VueI18n from 'vue-i18n'
import { messages } from './utils/i18n.js'
Vue.use(VueI18n)
// 实例化国际化插件
const i18n = new VueI18n({
  locale: "zh", //  设置地区
  messages  // 设置地区信息
})
Vue.use(Vueaxios,axios)
Vue.use(ElementUi)
Vue.config.productionTip = false
//引入mock文件
require('./mock/mock.js')

Vue.directive('drag', {
  inserted: function (ele) { 
    ele.onmousedown = function(ev){
      var x = ev.clientX - ele.offsetLeft;
      var y = ev.clientY - ele.offsetTop;
      var MaxX = document.documentElement.clientWidth - ele.offsetWidth
      var MaxY = document.documentElement.clientHeight - ele.offsetHeight
      document.onmousemove = function (ev1) {
        var x1 = ev1.clientX - x
        var y1 = ev1.clientY - y
        if (x1 > 0 && x1 < MaxX) { 
            ele.style.left = x1 +'px'
        }
        if (y1 > 0 && y1 < MaxY) { 
            ele.style.top=y1+'px'
        }
      }
      document.onmouseup = function () { 
        document.onmousemove = null
        document.onmouseup =null
      }
    }
  }

 })
//全局组件 注册
Vue.use(MyPlugin)

router.beforeEach((to, from, next)=> { 
  const data = localStorage.getItem('message')
          // 用来刚开始跳到 注册登录页面· ，
  if (!data && to.path !== '/login') { 
      next('/login')
  }
  next()
})



new Vue({
  beforeCreate() { 
    Vue.prototype.$bus = this,
    Vue.prototype.$echarts=echarts
  },
  router,
  i18n,
  render: h => h(App),
}).$mount('#app')
